<?php

declare(strict_types=1);

namespace App\Request\Admin;

use App\Constants\Admin\PermissionCode;
use App\Request\FormRequest;
use Hyperf\Validation\Rule;

class Permission extends FormRequest
{
    /**
     * 场景
     * @var array|\string[][]
     */
    protected array $scenes = [
        'save' => [
            'name',
            'menu_id',
            'path',
            'link',
            'status',
            'method',
            'method.*',
            'version'
        ],
        'update' => [
            'name',
            'menu_id',
            'path',
            'link',
            'status',
            'method',
            'method.*',
            'version'
        ],
        'destroy' => [
            'ids',
            'ids.*'
        ]
    ];

    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'name' => 'required|max:10',
            'menu_id' => 'required|numeric|min:1',
            'path' => 'required|path',
            'link' => 'nullable|path',
            'status' => 'in:0,1',
            'version' => [
                'required',
                Rule::in(['v1'])
            ],
            'ids' => 'required|array',
            'ids.*' => 'required|numeric|min:1',
            'method' => 'required|array',
            'method.*' => [
                'required',
                Rule::in(PermissionCode::$methodMap)
            ]
        ];
    }
}
